<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Clojure documentation browser</title><style>
.library
{
  padding: 0.5em 0 0 0 
}
.all-libs-toggle,.library-contents-toggle
{
 font-size: small;
}
.all-libs-toggle a,.library-contents-toggle a
{
 color: white
}
.library-member-doc-whitespace
{
 white-space: pre
}
.library-member-source-toggle
{
  font-size: small;
  margin-top: 0.5em
}
.library-member-source
{
  display: none;
  border-left: solid lightblue 
}
.library-member-docs
{
  font-family:monospace
}
.library-member-arglists
{
  font-family: monospace
}
.library-member-type
{
  font-weight: bold; 
  font-size: small;
  font-style: italic;
  color: darkred
}
.lib-links
{
  margin: 0 0 1em 0
}

.lib-link-header
{
  color: white;
  background: darkgreen;
  width: 100%
}

.library-name 
{ 
  color: white;
  background: darkblue;
  width: 100%
}

.missing-library
{
  color: darkred; 
  margin: 0 0 1em 0 
}

.library-members
{
  list-style: none
}

.library-member-name
{
  font-weight: bold;
  font-size: 105%
}</style><script language="JavaScript" type="text/javascript"> // <![CDATA[

function getElem(id)
{
  if( document.getElementById )
  {
    return document.getElementById( id )
  }
  else if ( document.all )
  {
    return eval( 'document.all.' + id )
  }
  else
    return false;
}

function setDisplayStyle(id,displayStyle)
{
  var elem = getElem (id)
  if (elem)
  {
    elem.style.display = displayStyle
  }

}

function setLinkToggleText (id, text)
{
 var elem = getElem (id)
 if (elem)
 {
   elem.innerHTML = text
 }
}

function collapse(id)
{
  setDisplayStyle (id, 'none')
}

function expand (id)
{
  setDisplayStyle (id, 'block')
}

function toggleSource( id )
{
  toggle(id, 'linkto-' + id, 'Hide Source', 'Show Source')
}

function toggle(targetid, linkid, textWhenOpen, textWhenClosed)
{
  var elem = getElem (targetid)
  var link = getElem (linkid)

  if (elem && link)
  {
    var isOpen = false
    if (elem.style.display == '')
    {
      isOpen = link.innerHTML == textWhenOpen
    }
    else if( elem.style.display == 'block' )
    {
      isOpen = true
    }
    
    if (isOpen)
    {
      elem.style.display = 'none'
      link.innerHTML = textWhenClosed
    }
    else
    {
      elem.style.display = 'block'
      link.innerHTML = textWhenOpen
    }
  }
}

      //]]>
</script><script language="JavaScript" type="text/javascript">// <![CDATA[!
function expandAllNamespaces()
{
expand(&apos;library-contents-server.dbm&apos;);
setLinkToggleText(&apos;library-contents-toggle-server.dbm&apos;, &apos;-&apos;);

}function collapseAllNamespaces()
{
collapse(&apos;library-contents-server.dbm&apos;);
setLinkToggleText(&apos;library-contents-toggle-server.dbm&apos;, &apos;+&apos;);

}
// ]]></script></head><body><div class="lib-links"><div class="lib-link-header">Namespaces<span class="all-libs-toggle"> [ <a href="javascript:expandAllNamespaces()">Expand All</a> ] [ <a href="javascript:collapseAllNamespaces()">Collapse All</a> ]</span></div><a class="lib-link" href="#library-server.dbm">server.dbm</a></div><div class="library"><a name="library-server.dbm"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-server.dbm" href="javascript:toggle(&apos;library-contents-server.dbm&apos;, &apos;library-contents-toggle-server.dbm&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>server.dbm</div><div class="library-contents" id="library-contents-server.dbm"><div class="library-member-links"><a class="lib-member-link" href="#member-server.dbm-create-record">create-record</a> <a class="lib-member-link" href="#member-server.dbm-delete-record">delete-record</a> <a class="lib-member-link" href="#member-server.dbm-get-deleted-record">get-deleted-record</a> <a class="lib-member-link" href="#member-server.dbm-get-fields-names">get-fields-names</a> <a class="lib-member-link" href="#member-server.dbm-get-fields-number">get-fields-number</a> <a class="lib-member-link" href="#member-server.dbm-get-record-size">get-record-size</a> <a class="lib-member-link" href="#member-server.dbm-get-records-offset">get-records-offset</a> <a class="lib-member-link" href="#member-server.dbm-is-deleted?">is-deleted?</a> <a class="lib-member-link" href="#member-server.dbm-read-fields-meta">read-fields-meta</a> <a class="lib-member-link" href="#member-server.dbm-read-one-record">read-one-record</a> <a class="lib-member-link" href="#member-server.dbm-read-records">read-records</a> <a class="lib-member-link" href="#member-server.dbm-read-records-not-deleted">read-records-not-deleted</a> <a class="lib-member-link" href="#member-server.dbm-read-str-len">read-str-len</a> <a class="lib-member-link" href="#member-server.dbm-records-number">records-number</a> <a class="lib-member-link" href="#member-server.dbm-records-number-not-deleted">records-number-not-deleted</a> <a class="lib-member-link" href="#member-server.dbm-set-position-append">set-position-append</a> <a class="lib-member-link" href="#member-server.dbm-set-position-record">set-position-record</a> <a class="lib-member-link" href="#member-server.dbm-set-position-record-not-deleted">set-position-record-not-deleted</a> <a class="lib-member-link" href="#member-server.dbm-unmap">unmap</a> <a class="lib-member-link" href="#member-server.dbm-update-record">update-record</a> <a class="lib-member-link" href="#member-server.dbm-write-record">write-record</a></div><ol class="library-members"><li class="library-member"><a name="member-server.dbm-create-record"/><dl class="library-member-table"><dt class="library-member-name">create-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name data])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Creates a new record, either in a previously deleted record space or a new one if no record appears as deleted</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-create-record&apos;)" id="linkto-membersource-server.dbm-create-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-create-record"><pre>(defn create-record
  &quot;Creates a new record, either in a previously deleted record space or a new one if no record appears as deleted&quot;
  [file-name data]
  (if (= (get-fields-number file-name) (count data))
    (with-open [file (RandomAccessFile. file-name &quot;rw&quot;)]
      (let [magic-number (.readInt file)
	    offset       (.readInt file)
	    num-fields   (.readShort file)
	    fields-data  (read-fields-meta file num-fields)
	    start-record (get-deleted-record file-name)]
	(if (= start-record -1)
	  (set-position-append file)
	  (set-position-record file file-name start-record))
	(write-record file file-name data fields-data)))
    -1))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-delete-record"/><dl class="library-member-table"><dt class="library-member-name">delete-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name RecNo])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Puts the record in a deleted state</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-delete-record&apos;)" id="linkto-membersource-server.dbm-delete-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-delete-record"><pre>(defn delete-record
  &quot;Puts the record in a deleted state&quot;
  [file-name RecNo]
  (with-open [file (RandomAccessFile. file-name &quot;rw&quot;)]
    (if (&lt;= RecNo (records-number-not-deleted file-name))
      (let [number 32768]
	(set-position-record-not-deleted file file-name (- RecNo 1))
	(.writeShort file number) 
	1)
      -1)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-get-deleted-record"/><dl class="library-member-table"><dt class="library-member-name">get-deleted-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns the RecNo of a deleted record</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-get-deleted-record&apos;)" id="linkto-membersource-server.dbm-get-deleted-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-get-deleted-record"><pre>(defn get-deleted-record
  &quot;Returns the RecNo of a deleted record&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [offset (get-records-offset file-name)
	  record-size (- (get-record-size file-name) 2)
	  records-max (records-number file-name)]
      (.seek file offset)
      (loop [result -1
	     count 0]
	(if (= result -1)
	  (if (&gt;= count records-max)
	    result
	    (if (is-deleted? file)
	      count
	      (let [next (+ (.getFilePointer file) record-size)]
		(.seek file next)
		(recur result (inc count)))))
	  result)))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-get-fields-names"/><dl class="library-member-table"><dt class="library-member-name">get-fields-names</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns the name of the fields</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-get-fields-names&apos;)" id="linkto-membersource-server.dbm-get-fields-names">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-get-fields-names"><pre>(defn get-fields-names
  &quot;Returns the name of the fields&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [magic-number (.readInt file)
	  offset       (.readInt file)
	  num-fields   (.readShort file)
	  fields-meta  (read-fields-meta file num-fields)]
      (loop [result []
	     fields fields-meta]
	(if (= () fields)
	  result
	  (recur (conj result (first(first fields))) (rest fields)))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-get-fields-number"/><dl class="library-member-table"><dt class="library-member-name">get-fields-number</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets how many fields exist in every record</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-get-fields-number&apos;)" id="linkto-membersource-server.dbm-get-fields-number">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-get-fields-number"><pre>(defn get-fields-number
  &quot;Gets how many fields exist in every record&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [magic-number (.readInt file)
	  offset (.readInt file)
	  num-fields (.readShort file)]
      num-fields)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-get-record-size"/><dl class="library-member-table"><dt class="library-member-name">get-record-size</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns the size of a record</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-get-record-size&apos;)" id="linkto-membersource-server.dbm-get-record-size">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-get-record-size"><pre>(defn get-record-size
  &quot;Returns the size of a record&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [magic-number (.readInt file)
	  offset       (.readInt file)
	  num-fields   (.readShort file)
	  fields-meta  (read-fields-meta file num-fields)]
      (loop [result 0
	     fields fields-meta]
	(if (= () fields)
	  (+ result 2)
	  (recur (+ (first(rest (first fields))) result) (rest fields)))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-get-records-offset"/><dl class="library-member-table"><dt class="library-member-name">get-records-offset</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets the offset where the records start in the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-get-records-offset&apos;)" id="linkto-membersource-server.dbm-get-records-offset">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-get-records-offset"><pre>(defn get-records-offset
  &quot;Gets the offset where the records start in the file&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [magic-number (.readInt file)
	  offset       (.readInt file)]
      offset)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-is-deleted?"/><dl class="library-member-table"><dt class="library-member-name">is-deleted?</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns if a record is deleted</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-is-deleted?&apos;)" id="linkto-membersource-server.dbm-is-deleted?">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-is-deleted?"><pre>(defn is-deleted?
  &quot;Returns if a record is deleted&quot;
  [file]
  (if (not (zero? (.readShort file)))
    true
    false))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-read-fields-meta"/><dl class="library-member-table"><dt class="library-member-name">read-fields-meta</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file num-fields])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Reads the meta-data of all the fields</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-read-fields-meta&apos;)" id="linkto-membersource-server.dbm-read-fields-meta">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-read-fields-meta"><pre>(defn read-fields-meta
  &quot;Reads the meta-data of all the fields&quot;
  [file num-fields]
  (loop [n num-fields
	 result []]
    (if (= n 0)
      result
      (let [name-len (.readShort file)
	    field-name (read-str-len file name-len)
	    field-len (.readShort file)]
	(recur (dec n) (conj result [field-name field-len]))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-read-one-record"/><dl class="library-member-table"><dt class="library-member-name">read-one-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file fields])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Reads one individual record from the file.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-read-one-record&apos;)" id="linkto-membersource-server.dbm-read-one-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-read-one-record"><pre>(defn read-one-record
  &quot;Reads one individual record from the file.&quot;
  [file fields]
  (loop 
      [result {:deleted (not (zero?(.readShort file)))}
       [[fname fsize] &amp; rest_fields] fields]
    (if fname  
      (recur (assoc result (keyword fname) (.trim (read-str-len file fsize)))
	     rest_fields)
      result)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-read-records"/><dl class="library-member-table"><dt class="library-member-name">read-records</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets all the records in the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-read-records&apos;)" id="linkto-membersource-server.dbm-read-records">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-read-records"><pre>(defn read-records
  &quot;Gets all the records in the file&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [magic-number (.readInt file)
	  offset       (.readInt file)
	  num-fields   (.readShort file)
	  fields-data  (read-fields-meta file num-fields)
	  record-size (- (get-record-size file-name) 2)]
      (loop [result []]
	(if (= (.getFilePointer file) (.length file))
	  result	 
          (recur (conj result (read-one-record file fields-data))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-read-records-not-deleted"/><dl class="library-member-table"><dt class="library-member-name">read-records-not-deleted</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets all the records that are not deleted in the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-read-records-not-deleted&apos;)" id="linkto-membersource-server.dbm-read-records-not-deleted">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-read-records-not-deleted"><pre>(defn read-records-not-deleted
  &quot;Gets all the records that are not deleted in the file&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [magic-number (.readInt file)
	  offset       (.readInt file)
	  num-fields   (.readShort file)
	  fields-data  (read-fields-meta file num-fields)
	  record-size (- (get-record-size file-name) 2)]
      (loop [result []]
	(if (= (.getFilePointer file) (.length file))
	  result
	  (if (is-deleted? file)
	    (let [next (+ (.getFilePointer file) record-size)]
	      (.seek file next)
	      (recur result))
	    (let [next (- (.getFilePointer file) 2)]
	      (.seek file next)
	      (recur (conj result (read-one-record file fields-data))))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-read-str-len"/><dl class="library-member-table"><dt class="library-member-name">read-str-len</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file n])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Read the next n bytes and create a string from it.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-read-str-len&apos;)" id="linkto-membersource-server.dbm-read-str-len">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-read-str-len"><pre>(defn read-str-len
  &quot;Read the next n bytes and create a string from it.&quot;
  [file n]
  (let [barray (byte-array n)]
    (.readFully file barray)
    (String. barray)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-records-number"/><dl class="library-member-table"><dt class="library-member-name">records-number</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets the number of records in the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-records-number&apos;)" id="linkto-membersource-server.dbm-records-number">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-records-number"><pre>(defn records-number
  &quot;Gets the number of records in the file&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (/ (- (.length file) (get-records-offset file-name)) (get-record-size file-name))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-records-number-not-deleted"/><dl class="library-member-table"><dt class="library-member-name">records-number-not-deleted</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets the number of records that are not deleted in the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-records-number-not-deleted&apos;)" id="linkto-membersource-server.dbm-records-number-not-deleted">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-records-number-not-deleted"><pre>(defn records-number-not-deleted
  &quot;Gets the number of records that are not deleted in the file&quot;
  [file-name]
  (with-open [file (RandomAccessFile. file-name &quot;r&quot;)]
    (let [offset (get-records-offset file-name)
	  size (- (get-record-size file-name) 2)
	  records (records-number file-name)]
      (.seek file offset)
      (loop [record records
	     count 0]
	(if (= record 0)
	  count
	  (if (is-deleted? file)
	    (let [next (+ size (.getFilePointer file))]  
	      (.seek file next)
	      (recur (dec record) count))
	    (let [next (+ size (.getFilePointer file))]  
	      (.seek file next)
	      (recur (dec record) (inc count)))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-set-position-append"/><dl class="library-member-table"><dt class="library-member-name">set-position-append</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Moves the file pointer to the end of the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-set-position-append&apos;)" id="linkto-membersource-server.dbm-set-position-append">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-set-position-append"><pre>(defn set-position-append
  &quot;Moves the file pointer to the end of the file&quot;
  [file]
  (let [position (.length file)]
    (.seek file position)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-set-position-record"/><dl class="library-member-table"><dt class="library-member-name">set-position-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file file-name RecNo])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Moves the file pointer to the n record position</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-set-position-record&apos;)" id="linkto-membersource-server.dbm-set-position-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-set-position-record"><pre>(defn set-position-record
  &quot;Moves the file pointer to the n record position&quot;
  [file file-name RecNo]
  (let [position (+ (get-records-offset file-name) (*(get-record-size file-name) RecNo))]
    (.seek file position)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-set-position-record-not-deleted"/><dl class="library-member-table"><dt class="library-member-name">set-position-record-not-deleted</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file file-name RecNo])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets the number of records that are not deleted in the file</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-set-position-record-not-deleted&apos;)" id="linkto-membersource-server.dbm-set-position-record-not-deleted">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-set-position-record-not-deleted"><pre>(defn set-position-record-not-deleted
  &quot;Gets the number of records that are not deleted in the file&quot;
  [file file-name RecNo]
  (let [offset (get-records-offset file-name)
	size (- (get-record-size file-name) 2)]
    (.seek file offset)
    (loop [count 0]
      (if (= count RecNo)
	(if (is-deleted? file)
	  (let [next (+ size (.getFilePointer file))]  
	    (.seek file next)
	    (recur count))
	  (.seek file (- (.getFilePointer file) 2)))
	(if (is-deleted? file)
	  (let [next (+ size (.getFilePointer file))]  
	    (.seek file next)
	    (recur count))
	  (let [next (+ size (.getFilePointer file))]  
	    (.seek file next)
	    (recur (inc count))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-unmap"/><dl class="library-member-table"><dt class="library-member-name">unmap</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name data])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns a vector from a map in the order of the fields</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-unmap&apos;)" id="linkto-membersource-server.dbm-unmap">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-unmap"><pre>(defn unmap
  &quot;Returns a vector from a map in the order of the fields&quot;
  [file-name data]
  (loop [records []
	 fields (get-fields-names file-name)]
    (if (= () fields)
      records
      (recur (conj records (data (keyword (first fields)))) (rest fields)))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-update-record"/><dl class="library-member-table"><dt class="library-member-name">update-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name RecNo data])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Updates a record based on a complete record it receives</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-update-record&apos;)" id="linkto-membersource-server.dbm-update-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-update-record"><pre>(defn update-record
  &quot;Updates a record based on a complete record it receives&quot;
  [file-name RecNo data]
  (if (= (get-fields-number file-name) (count data))
    (with-open [file (RandomAccessFile. file-name &quot;rw&quot;)]
      (if (&lt;= RecNo (records-number-not-deleted file-name))	
	(let [number 32768
	      magic-number (.readInt file)
	      offset       (.readInt file)
	      num-fields   (.readShort file)
	      fields-data  (read-fields-meta file num-fields)]
	  (set-position-record-not-deleted file file-name (- RecNo 1))
	  (write-record file file-name data fields-data)
	  1)
	-1))
    -2))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-server.dbm-write-record"/><dl class="library-member-table"><dt class="library-member-name">write-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file file-name data fields-data])</span></div><div class="library-member-docs"><div class="library-member-doc-line">writes a record</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-server.dbm-write-record&apos;)" id="linkto-membersource-server.dbm-write-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-server.dbm-write-record"><pre>(defn write-record
  &quot;writes a record&quot;
  [file file-name data fields-data]
  (.writeShort file 0)
  (loop [fields fields-data
	 data-towrite (unmap file-name data)]
    (if (= () fields)
      1
      (let [towrite (first data-towrite)
	    size (first (rest (first fields)))]
	(.write file (byte-array size (.getBytes towrite)))
	(recur (rest fields) (rest data-towrite))))))</pre></div></div></dd></dl></li></ol></div></div></body></html>